﻿using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

namespace EasoScreenClient;

public partial class MainPage : ContentPage
{

    public MainPage()
    {
        InitializeComponent();
    }

    private async void OnSubmitBtnClicked(object sender, EventArgs e)
    {
        string xml = $"<Task Name=\"{NameEntry.Text}\" Time=\"{TimeEntry.Text}\" Date=\"{DateEntry.Text}\"/>";
        using var client = new HttpClient();
        var content = new StringContent(xml, Encoding.UTF8, "text/plain");
        try
        {
            var response = await client.PostAsync($"http://{IPEntry.Text}/plugins/scheduler", content);
            if (response.IsSuccessStatusCode)
            {
                await DisplayAlert("成功", "任务已提交", "确定");
            }
            else
            {
                await DisplayAlert("错误", $"提交失败: {response.StatusCode}", "确定");
            }
        }
        catch (Exception ex)
        {
            await DisplayAlert("异常", $"提交时发生异常: {ex.Message}", "确定");
        }
    }
}

